using System;
using System.ComponentModel;
using System.Web.UI;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;

namespace WebChart
{
	[TypeConverter(typeof(ExpandableObjectConverter)), PersistenceMode(PersistenceMode.InnerProperty)]
	public class ChartLine
	{
		// Fields
		private Color color;
		private CustomLineCap customEndCap;
		private CustomLineCap customStartCap;
		private DashStyle dashStyle;
		private LineCap endCap;
		private LineJoin lineJoin;
		private LineCap startCap;
		private float width;

		// Methods
		public ChartLine() : this(Color.Black)
		{
		}

		public ChartLine(Color color)
		{
			this.dashStyle = DashStyle.Solid;
			this.lineJoin = LineJoin.Miter;
			this.startCap = LineCap.Flat;
			this.endCap = LineCap.Flat;
			this.customStartCap = null;
			this.customEndCap = null;
			this.width = 0f;
			this.color = color;
		}

		public Pen GetPen(Graphics graphics)
		{
			Pen pen = new Pen(graphics.GetNearestColor(this.color));
			pen.StartCap = this.startCap;
			pen.EndCap = this.endCap;
			if (this.customStartCap != null)
			{
				pen.CustomStartCap = this.customStartCap;
			}
			if (this.customEndCap != null)
			{
				pen.CustomEndCap = this.customEndCap;
			}
			pen.DashStyle = this.dashStyle;
			pen.Width = this.width;
			return pen;
		}

		public override string ToString()
		{
			return string.Format(CultureInfo.InvariantCulture, "{0}-{1}", new object[] { this.dashStyle.ToString(CultureInfo.InvariantCulture), this.color.Name });
		}

		// Properties
		[DefaultValue(typeof(Color), "Black"), Category("Appearance"), NotifyParentProperty(true)]
		public Color Color
		{
			get
			{
				return this.color;
			}
			set
			{
				this.color = value;
			}
		}

		[Category("Appearance"), NotifyParentProperty(true), DefaultValue((string) null)]
		public CustomLineCap CustomEndCap
		{
			get
			{
				return this.customEndCap;
			}
			set
			{
				this.customEndCap = value;
			}
		}

		[NotifyParentProperty(true), DefaultValue((string) null), Category("Appearance")]
		public CustomLineCap CustomStartCap
		{
			get
			{
				return this.customStartCap;
			}
			set
			{
				this.customStartCap = value;
			}
		}

		[Category("Appearance"), NotifyParentProperty(true), DefaultValue(0)]
		public DashStyle DashStyle
		{
			get
			{
				return this.dashStyle;
			}
			set
			{
				this.dashStyle = value;
			}
		}

		[DefaultValue(0), NotifyParentProperty(true), Category("Appearance")]
		public LineCap EndCap
		{
			get
			{
				return this.endCap;
			}
			set
			{
				this.endCap = value;
			}
		}

		[NotifyParentProperty(true), DefaultValue(0), Category("Appearance")]
		public LineJoin LineJoin
		{
			get
			{
				return this.lineJoin;
			}
			set
			{
				this.lineJoin = value;
			}
		}

		[DefaultValue(0), Category("Appearance"), NotifyParentProperty(true)]
		public LineCap StartCap
		{
			get
			{
				return this.startCap;
			}
			set
			{
				this.startCap = value;
			}
		}

		[DefaultValue((float) 0f), Category("Appearance"), NotifyParentProperty(true)]
		public float Width
		{
			get
			{
				return this.width;
			}
			set
			{
				this.width = value;
			}
		}
	}
}
